package com.macaline.framemarker.plugin.pluginManager.manager;


import com.macaline.framemarker.plugin.pluginManager.PluginRegister;
import com.macaline.framemarker.plugin.pluginManager.interfacer.PluginMenuInterface;

import java.util.Iterator;
import java.util.List;

/**
 * 后台插件菜单显示页面
 */
public class PluginMenuGenerator implements PluginMenuInterface {

    /**
     * 首页插件菜单的名称
     */
    private String pluginMenuName = "插件列表";

    @Override
    public String generateMenuHtml(List<PluginRegister> list) {
        PluginRegister pluginRegister;
        Iterator<PluginRegister> iterator = list.iterator();
        StringBuffer menuString = new StringBuffer("");
        menuString.append("<li class=\"layui-nav-item\" onclick=\"lock()\">\n");
        menuString.append("     <a href=\"javascript:;\">\n");
        menuString.append("          <i class=\"layui-icon firstMenuIcon\">&#xe635;</i>\n");
        menuString.append("          <span class=\"firstMenuFont\">" + pluginMenuName + "\n");
        menuString.append("                 <span class=\"layui-badge-dot\" id=\"account\" style=\"display: none;\"></span>\n");
        menuString.append("          </span>\n");
        menuString.append("     </a>\n");
        menuString.append("     <dl class=\"layui-nav-child\">\n");
        while (iterator.hasNext()){
            pluginRegister = iterator.next();
        menuString.append("          <dd><a class=\"subMenuItem\" href=\"javascript:loadUrl('" + pluginRegister.url() + "');\">" + pluginRegister.name() + "</a></dd>\n");
        }
        menuString.append("     </dl>\n");
        menuString.append("</li>\n");
        return menuString.toString();
    }
}
